/**
 * 
 */
/**
 * @author Administrator
 *
 */
package app.dao;

import java.util.List;
import java.util.Map;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Repository;

import app.util.Log;
import app.util.Util;
import app.util.UtilDbOracle;
import net.sf.json.JSONArray;

@Repository
public class BaseDao {

	@Autowired
	private JdbcTemplate primaryJdbcTemplate;

	public JSONArray listBase(String sql) {
		Log.outLog(sql);
		JSONArray result = new JSONArray();
		try {
			List<Map<String, Object>> qList = primaryJdbcTemplate.queryForList(sql);
			result = Util.list_to_JSONArray(qList);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}
	
	public JSONArray listSqlOracle(String sql) {
		Log.outLog(sql);
		JSONArray result = new JSONArray();
		try {
			result = UtilDbOracle.list(sql);
		} catch (Exception e) {
			e.printStackTrace();
		}
		return result;
	}
	
	

	public boolean execute(String sql) {
		Log.outLog(sql);
		boolean result = false;
		int executeR = primaryJdbcTemplate.update(sql);
		if (executeR > 0) {
			result = true;
		}

		insertLog(sql);

		return result;
	}
	

	
	

	public void insertLog(String operatSql) {
		String operateType = "";
		if (operatSql.startsWith("insert") || operatSql.startsWith("INSERT")) {

			operateType = "插入";
		}
		if (operatSql.startsWith("update") || operatSql.startsWith("UPDATE")) {
			operateType = "修改";
		}
		if (operatSql.startsWith("delete") || operatSql.startsWith("DELETE")) {
			operateType = "删除";
		}
		operatSql = operatSql.replace("'", "");
	}

}